#include "bsp_g3507std.h"
#include "ti_msp_dl_config.h"
#include "user_main.h"


uint32_t g_g3507_board_order_array[G3507_BOARD_ORDER_ARRAY_LEN];
uint32_t g_g3507_board_sensor_array[G3507_BOARD_SENSOR_ARRAY_LEN];

////////////////////////////////////
////////////////////////////////////
//RTC
DL_RTC_Calendar gRTCCalendarConfig;
void set_calendar_timer(DL_RTC_Calendar gRTCCalendarConfig)
{
    DL_RTC_disableClockControl(RTC);       //关闭RTC
    DL_RTC_initCalendar(RTC , gRTCCalendarConfig, DL_RTC_FORMAT_BINARY);  //初始化RTC时间
    DL_RTC_enableClockControl(RTC);
}

DL_RTC_Calendar gRTCCalendar;
void get_calendar_timer(DL_RTC_Calendar *gRTCCalendar)
{
    *gRTCCalendar = DL_RTC_getCalendarTime(RTC);
}

int g3507_board_get_sensor( uint32_t *board_sensor_array , uint32_t board_sensor_array_len  )
{
    get_calendar_timer(&gRTCCalendar);

    board_sensor_array[0] = gRTCCalendar.seconds;
    board_sensor_array[1] = gRTCCalendar.minutes;
    board_sensor_array[2] = gRTCCalendar.hours;
    board_sensor_array[3] = gRTCCalendar.dayOfWeek;
    board_sensor_array[4] = gRTCCalendar.dayOfMonth;
    board_sensor_array[5] = gRTCCalendar.month;
    board_sensor_array[6] = gRTCCalendar.year;
    
    return 0;
}

int g3507_board_set_order( uint32_t *board_order_array  , uint32_t board_order_array_len  )
{
    gRTCCalendarConfig.seconds    = board_order_array[0];
    gRTCCalendarConfig.minutes    = board_order_array[1];
    gRTCCalendarConfig.hours      = board_order_array[2];
    gRTCCalendarConfig.dayOfWeek  = board_order_array[3];
    gRTCCalendarConfig.dayOfMonth = board_order_array[4];
    gRTCCalendarConfig.month      = board_order_array[5];
    gRTCCalendarConfig.year       = board_order_array[6];
    
    set_calendar_timer(gRTCCalendarConfig);
    return 0;
}
